package com.taiji.redispractise.service.Impl;

import com.taiji.redispractise.domain.*;
import com.taiji.redispractise.mapper.*;
import com.taiji.redispractise.service.MybatisService;
import com.taiji.redispractise.service.RedisService;
import com.taiji.redispractise.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.Jedis;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class MybatisServiceImpl implements MybatisService {

    @Autowired
    private S1TeacherMapper teacherMapper;

    @Autowired
    private RedisService redisService;


    @Override
    public List<S1Teacher> getTeacherAll() {
        List<S1Teacher> teachers = teacherMapper.selectAll();
        redisService.set("teachers", teachers);
        return redisService.get("teachers",List.class);
    }

    @Override
    public List<S1Teacher> getTeacherAllHash() {
        List<S1Teacher> teachers = teacherMapper.selectAll();
        redisService.hset("teacherHash", "teacher", teachers);
        return redisService.hget("teacherHash", "teacher", List.class);
    }

    @Override
    public List<S1Teacher> getTeacherAllList() {
        List<S1Teacher> teachers = teacherMapper.selectAll();
        redisService.lpust("teacherList", teachers);
        return redisService.lindex("teacherList",0,List.class);
    }
}
